let app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        year: '',
        type1:app.globalData.rootUrl+'/static/dangyang/1.png',
        type2:app.globalData.rootUrl+'/static/dangyang/2.jpg',
        type3:app.globalData.rootUrl+'/static/dangyang/3.png',
        type4:app.globalData.rootUrl+'/static/dangyang/4.png',
        type5:app.globalData.rootUrl+'/static/dangyang/5.png',
        type6:app.globalData.rootUrl+'/static/dangyang/6.png',
        typeValue:[],
        affiche:[],
        oldPassword:"",
        newPassword:"",
        confirmPassword:"",
        showPassword:false,
        readHelp:0,
        readAssist:0,
        survey:0,
        statisticsAuto:0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: async function (options) {
        
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        // let cookie = wx.getStorageSync('cookie');
        // if(cookie){
        //     let now = new Date();
        //     this.setData({ year: now.getFullYear()});
        //     this.init();
        // }else{
        //     wx.navigateTo({ url: '/pages/login/login' });
        // }
        let now = new Date();
        this.setData({ year: now.getFullYear()});
        this.init();

    },

    //跳转帮扶概况
    toHelpAll:function(e){
      wx.navigateTo({ url: `/pages/helpAll/helpAll` })
    },

    async init(){
        let params = { appid: app.globalData.appid, year: this.data.year };
        //获取banner图片
        await app.request('post', '/api/admin/bannerApi', {appid: app.globalData.appid})
        .then(res => {
            this.setData({ banner: res.data.data});
        }).catch(err => console.log(err));
        
        //获取项目数
        await app.request('post', '/api/project/libraryCount', {appid: app.globalData.appid})
        .then(res => {
            this.setData({ typeValue: res.data.typeValue,readHelp:res.data.readHelp,readAssist:res.data.readAssist,survey:res.data.survey,statisticsAuto:res.data.statisticsAuto});
        }).catch(err => console.log(err));

        //获取公共栏
        await app.request('post', '/api/admin/afficheApi', {appid: app.globalData.appid})
        .then(res => {
            this.setData({ affiche: res.data.data});
        }).catch(err => console.log(err));

    },


    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },

    afficheDetail:function(e){
      var path = e.currentTarget.dataset.path;

      wx.downloadFile({
        // 示例 url，并非真实存在
        url: path,
        success: function (res) {
          const filePath = res.tempFilePath
          wx.openDocument({
            filePath: filePath,
            success: function (res) {
            }
          })
        }
      })

        // wx.navigateTo({ url: `/pages/affiche/affiche?id=${e.currentTarget.dataset.id}` })
    },

    //操作手册
    showManual:function(){
        wx.navigateTo({ url: `/pages/showManual/showManual?id=1` })
    },

    //跳转统计页面
    rankingMain:function(){
        wx.navigateTo({ url: `/pages/rankingMain/rankingMain` })
    },

    //走访统计
    datas:function(){
        wx.navigateTo({ url: `/pages/datas/datas` })
    },

    //跳转项目列表页
    toProjectList:function(e){
        wx.navigateTo({ url: `/pages/projectList/projectList?libraryTab=${e.currentTarget.dataset.id}` })
    },

    //跳转求助页面
    toHelp:function(e){
        wx.navigateTo({ url: `/pages/help/help` })
    },

    //跳转数据分析
    statistics:function(){
        wx.navigateTo({ url: `/pages/statistics/statistics` })
    },

    //跳转惠企政策
    toPolicy:function(){
      wx.navigateTo({ url: `/pages/policy/policy` })
    },

    //跳转求助列表
    toHelpList:function(e){
        if(e.currentTarget.dataset.status!=undefined){
            wx.navigateTo({ url: `/pages/helpList/helpList?status=${e.currentTarget.dataset.status}` })
        }
        if(e.currentTarget.dataset.type!=undefined){
            wx.navigateTo({ url: `/pages/helpList/helpList?type=${e.currentTarget.dataset.type}` })
        }
    },

    //跳转实时监控页面
    toMonitor:function(){
        wx.navigateTo({ url: `/pages/monitorList/monitorList` })
    },


    //跳转修改密码
    updatePassword:function(e){
        this.setData({showPassword:true});
    },

    //取消操作
    cancelButton:function(e){
        this.setData({showPassword:false});
    },

    //确定操作 
    confirmButton:function(e){
       
        let oldPassword = this.data.oldPassword;
        let newPassword = this.data.newPassword;
        let confirmPassword = this.data.confirmPassword;
        var self = this;
        var params = { oldPassword:oldPassword,newPassword:newPassword,confirmPassword:confirmPassword};
        app.request('post', '/api/Project/updatePassword', params).then(res => {
            app.showFailToast('修改成功');
            // showPassword:false,
            self.setData({oldPassword:'',newPassword:'',confirmPassword:''});
        }).catch(err => console.log(err));
      
     
    }
})